package pl.edu.pw.MidEmu.Common;

/**
 * Helper class used for string oiperations
 * @author Mateusz Starodab
 *
 */
public class StringHelper
{
	/**
	 * * pad a string S with a size of N with char C * on the left (True) or on
	 * the right(flase)
	 */
	public static synchronized String padString(String s, int n, char c, boolean paddingLeft)
	{
		StringBuffer str = new StringBuffer(s);
		int strLength = str.length();
		if (n > 0 && n > strLength)
		{
			for (int i = 0; i <= n; i++)
			{
				if (paddingLeft)
				{
					if (i < n - strLength)
						str.insert(0, c);
				}
				else
				{
					if (i > strLength)
						str.append(c);
				}
			}
		}
		return str.toString();
	}
}
